
function nodePlacementInit(){
	
}

//after placing a child, when the child is going to place its own children, have it move over half
	//the width of the width of the assist nodes it has
	//The position of the assist nodes is transparent to the parent placing its children
	//The children themselves compensate for it.
Node.prototype.placeChildren = function (){
			
	//layout: places parent in the center of the width of its children
		
	//if no children, return
	//if only child, place immediately below, regardless of width
	//else
	//add widths of all children and subtract half of widths of each end child (why?)
		//that is the separation of two widest children nodes
	//place left child at that distance
	//place next child at a distance  of one node plus the distance taken up by
		//the space of the the children between them.  Formula: (left child width)/2 + (next child width)/2
	//the last child should end up at the same distance away from the parent as the first child
	//finally, place children of each child node the same way		
			
	//the vertical offset should be a function of the number of children a node has, to make room for
		//the arrows, which must be clickable				
			
	/////////////////////////
	
	//if no children, nothing to do, so return
	if(this.children.length === 0){
		return false;
	}

	var currentChild = this.children[0];
	var numKids = this.children.length;
	var parentY = this.top;	
	
	//vertical offset
	var offsetY = parentY + this.displayedDiv.offsetHeight + 25 + (5 * (numKids -1) );

	//place immediately below if only child
	if(numKids == 1 && currentChild.assists.length ==0){
		currentChild.left = this.left;
		currentChild.top = offsetY;
		currentChild.placeChildren();
		return;
	}
	//else
			
	//horizontal position
		//every parent is centered in the middle of its width

	//offsetX to start out with, which will go to left most child
	var offsetX = this.left - (this.widthChildren/2);

	//var previousLeft = currentChild.left; //this makes it so don't have to wait for
											// position to change due to transition
	/*
	 * Place first child with certain offset
	 * That offset gets reduced, into negative, as go through children
	 * 
	 * Start with just half the width of parent as offset
	 * Before placing self, add half of your own width to that number
	 * after placing self, add half of your own width to that number
	 * 
	 * Have a child move itself to make room for its assists
	 * 
	 * have a width total, a width children, and a with assists
	 */
	var i = 0;
	var j = 0;
	var numAssists = 0;
	var currentChildLeft = 0;
	var currentAssist;
	while(i < numKids){
		currentChild = this.children[i];
		offsetX += currentChild.widthChildren/2;
		
		currentChild.left = offsetX;
		currentChildLeft = currentChild.left;
		currentChild.top = offsetY;
		
		offsetX += currentChild.widthChildren/2;
		
		currentChild.placeChildren();

		//place assists
			//it's a mess, I'm sorry
			j = 0;
			numAssists = currentChild.assists.length;
			//adjust position to make room for assist nodes
			//place assists basically like placed children
			while(j < numAssists){
				currentAssist = currentChild.assists[j];
				offsetX += currentAssist.widthTotal/2;
				currentAssist.left = offsetX;
				offsetX += currentAssist.widthTotal/2

				currentAssist.top = offsetY;
				currentAssist.placeChildren();
				j++;
			}
		i++;
	}
}

function updateHeight(node){
	//check if div changed size to accomodate text.  If so, reposition children
	if(node.oldHeight !== node.displayedDiv.offsetHeight){
		claim.placeChildren();
		claim.drawConnections();
	}
	node.oldHeight = node.displayedDiv.offsetHeight;
}

Node.prototype.updateWidth = function (change, yesChild){
	//always add to total
	this.widthTotal += change;
	
	//there are two trackers of width.  One for children only, one for total.  Only add to children if not an assist
		//the different trackers made node placement easier 
	if(yesChild){
		this.widthChildren += change;
	}
	
	//send increase up through to top of tree
		//must check again if assist or child to parent
	if(this.parent){
		if(this.displayedDiv.classList.contains("assist") ){
			this.parent.updateWidth(change, false);
		}else{
			this.parent.updateWidth(change, true);
		}
	}
}


